class UsersController < ApplicationController
	
	#before_filter :check_user_type, :only => [:index]
	
	# def check_user_type
		# @_current_user ||= session[:user_id] &&  User.find(session[:user_id]) 
		# if @_current_user.user_type == "student"
			# redirect_to "/"
			##scotty: you now need to call this method
		# end
	# end
	
	# def login 
		# if @user = User.authenticate(params[:email], params[password])
			# reset_session
			# session[:user_id] = @user_id
			# redirect_to home_url
		# end
	# end
	
	def logout
		session[:user] = nil
		redirect_to :action => "login"
	end
	
	def login
	end
	
	def ta_application
		if params[:ta_position] == nil &&
		params[:ta_semester] == nil
			redirect_to "/semesters"
		else
			if session[:user] != nil
				flash[:notice] = "You have already signed up for a semester.  (this doesnt check WHICH semester yet.)"
				redirect_to "/users/#{session[:user].id}"
			else
				@user = User.new(
				:user_type => "student",
				
				# All information below is test data for easy debugging, remove!
				:first_name => 			"testFirstName",
				:middle_initial => 		"M",
				:last_name => 			"testLastName",
				:univ_id => 			"000000000",
				:email => 				"email@test.com",
				:password =>			"test",
				:perm_phone => 			"000-000-0000",
				:campus_phone => 		"111-111-1111",
				:perm_address => 		"testPermanent address",
				:perm_city => 			"testCity",
				:perm_state => 			"XX",
				:perm_zip => 			"00000",
				:ta_curr_major  => 		"testCurrent Major",
				:ta_entry_semester => 	"Fall",
				:ta_entry_year => 		"1111",
				:ta_app_type => 		"MS",
				:ta_position =>			params[:ta_position],
				:ta_semester => 		params[:ta_semester],
				:currently_ta => 		"t",
				:ta_curr_course => 		"test000",
				:ta_curr_instructor => 	"Bob Tester",
				:ta_experience_1 => 	"test001",
				:ta_experience_2 => 	"test002",
				:ta_experience_3 => 	"test003",
				:ta_experience_4 => 	"test004",
				:ta_experience_5 => 	"test005",
				:ta_pass_mei => 		"t",
				:ta_curr_umei => 		"f",
				:ta_ms_degree => 		"t",
				:ta_course_request_1 => "101",
				:ta_course_request_2 => "102",
				:ta_course_request_3 => "103",
				:ta_additional_info => 	"test Additonal Information",
				:ta_signature => 		"testSignature")
				
				#@user = User.new(:user_type => "student")
			end
		end
	end
	
	def submit_app
		@user = User.new(params[:user])
		if @user.save
			session[:user] = @user
			redirect_to "/users/#{@user.id}"
		else
			render :template => "users/ta_application"
		end
	end
	def show
		#@user = User.find_by_id(params[:id])
		if session[:user] != nil 
			@user = session[:user]
		else
			redirect_to :action=> 'login'
		end
	end
	def index
		@users = User.find(:all)
	end
	def authenticate
		@user = User.new(params[:userform])
		valid_user = User.find(:first,:conditions => ["email = ? and password = ?", @user.email, @user.password])
		if valid_user
			session[:user] = valid_user
			redirect_to "/users/#{valid_user.id}"
		else
			flash[:notice] = "Invalid User/Password"
			redirect_to :action=> 'login'
		end
    end
end
	